import Axios from "axios"
import {url} from "./config.js"

Axios.defaults.timeout=60000

const HttpGet=async(options)=>{
    try{
        return Axios({
            method:"GET",
            url:`${url}${options.url}`,
            params:options.params,
            headers:{
                token:localStorage.getItem("token")
            }
        })
    }catch (error) {
        throw error;
    }
}

const HttpPost=async(options)=>{
    try{
        return Axios({
            method:"POST",
            url:`${url}${options.url}`,
            params:options.params,
            headers:{
                token:localStorage.getItem("token")               
            }
        })
    }catch (error) {
        throw error;
    }
}

const UPLoad=async(options)=>{
    try{
        return Axios({
            method:"POST",
            url:`${url}${options.url}`,
            data:options.params.formData,
            headers:{
                token:localStorage.getItem("token"),
                'Content-Type': 'multipart/form-data'      
            }
        })
    }catch (error) {
        throw error;
    }
}

//文件下载
const exportFileRequest = async(options)=>{
    try{
        return Axios({
            method:"POSt",
            url:`${url}${options.url}`,
            params:options.params,
            //responseType: 'blob',
            responseType: 'arraybuffer', 
            headers:{
                token:localStorage.getItem("token"),     
            }
        })
    }catch (error) {
        throw error;
    }
}

export {
    HttpGet,
    HttpPost,
    UPLoad,
    exportFileRequest
}
